package com.zcxy.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.zcxy.anotation.Log;
import com.zcxy.core.bean.PageQuery;
import com.zcxy.core.bean.Response;
import com.zcxy.sys.entity.SysLog;
import com.zcxy.sys.pojo.SysLogVo;
import com.zcxy.sys.service.ISysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * @author zcc
 * @version 1.0.0
 * @ClassName SysLogController.java
 * @Description 系统日志表
 * @createTime 2020-06-04
 */
@RestController
@RequestMapping("/api/sysLog")
@Api(tags = "系统日志表管理")
@Slf4j
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SysLogController {
    @Autowired
    private ISysLogService iSysLogService;

    @Log(value = "获取(系统日志表)分页数据列表")
    @PostMapping(value = "/queryPageList")
    @ApiOperation(value = "获取(系统日志表)分页数据列表", notes = "获取(系统日志表)分页数据列表")
    public Response<IPage<SysLogVo>> queryPageList(@RequestBody PageQuery<SysLog> queryVo) {
        return Response.ok(iSysLogService.queryPageList(queryVo));
    }


    @Log(value = "新增(系统日志表)数据")
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增(系统日志表)数据", notes = "新增(系统日志表)数据")
    public Response addSysLog(@RequestBody @Validated SysLog queryVo) {
        iSysLogService.addSysLog(queryVo);
        return Response.ok();
    }

    @Log(value = "修改(系统日志表)数据")
    @PutMapping(value = "/update")
    @ApiOperation(value = "修改(系统日志表)数据", notes = "修改(系统日志表)数据")
    public Response updateSysLog(@RequestBody @Validated SysLog queryVo) {
        iSysLogService.updateSysLog(queryVo);
        return Response.ok();
    }

    @Log(value = "删除(系统日志表)数据")
    @PostMapping(value = "/del")
    @ApiOperation(value = "根据主键删除(系统日志表)数据", notes = "根据主键删除(系统日志表)数据")
    public Response removeSysLog(@RequestParam("id") String id) {
        iSysLogService.removeSysLog(id);
        return Response.ok();
    }

    @Log(value = "批量删除(系统日志表)数据")
    @DeleteMapping(value = "/dels")
    @ApiOperation(value = "批量删除(系统日志表)数据", notes = "批量删除(系统日志表)数据")
    public Response removeSysLogs(@RequestBody List<String> ids) {
        iSysLogService.removeAllSysLog(ids);
        return Response.ok();
    }

    @Log(value = "查看(系统日志表)")
    @GetMapping(value = "/view")
    @ApiOperation(value = "查看(系统日志表)数据", notes = "查看(系统日志表)数据")
    public Response<SysLog> viewSysLog(@RequestParam("id") String id) {
        return Response.ok(iSysLogService.getBaseMapper().selectById(id));
    }

    @Log("导出系统日志表")
    @ApiOperation("导出系统日志表")
    @PostMapping(value = "/download")
    public void download(HttpServletResponse response, @RequestBody SysLog queryVo) throws IOException {
        iSysLogService.download(queryVo, response);
    }

}
